<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui">

    <ui:decorate template="/resources/template/modelo.xhtml">

        <ui:define name="centro">
            <f:view encoding="ISO-8859-1">  
                <h:form id="form">
                    <p:messages id="messages1" showDetail="true" autoUpdate="true" closable="true" escape="false" /> 
                    <p:panel id="pInfBasicas"  header="Cadastro de Periódicos de Gestão Social" style="width: 95%;background-color: #E0E0E0" >
                        <div algin="center" >
                            <h:panelGrid columns="2" width="99%" style="text-align: center" >
                                <h:outputText value="Nome da Revista: " style="width: 20%" />
                                <p:inputText value="#{periodicoGSBean.periodico.nomeRevista}" style="width: 80%" /> 
                                <h:outputText value="Vinculação Intituicional:" style="width: 20%" />
                                <p:selectOneMenu value="#{periodicoGSBean.periodico.instituicao.id}" style="width:80%"  
                                                 effect="fade"  filter="true" filterMatchMode="startsWith" >  
                                    <f:selectItem itemLabel="Selecione" itemValue="" noSelectionOption="true"  />  
                                    <f:selectItems value="#{instituicaoBean.listaInstituicoes}" var="inst" itemLabel="#{inst.nome}, #{inst.municipio},  #{inst.estado}" itemValue="#{inst.id}" />
                                </p:selectOneMenu>
                                <h:outputText value="Ano de Início: " style="width: 20%" /> 
                                <p:inputText value="#{periodicoGSBean.periodico.anoInicio}" style="width: 80%" /> 
                                <h:outputText value="Periodicidade: " style="width: 20%" /> 
                                <p:inputText value="#{periodicoGSBean.periodico.periodicidade}" style="width: 80%" /> 
                                <h:outputText value="Tipo de Publicação: " style="width: 20%" /> 
                                <p:selectOneRadio value="#{periodicoGSBean.periodico.tipoPublicacao}"  style="width: 80%;">  
                                    <f:selectItem itemLabel="Impressa" itemValue="Impressa" />  
                                    <f:selectItem itemLabel="Online" itemValue="Online" />  
                                    <f:selectItem itemLabel="Impressa e Online" itemValue="Impressa e Online" />  
                                </p:selectOneRadio> 
                                <h:outputText value="Disponível no link: " style="width: 20%" /> 
                                <p:inputText value="#{periodicoGSBean.periodico.link}" style="width: 80%" /> 
                                <h:outputText  value="Indexadores: " style="width: 20%" /> 
                                <p:selectCheckboxMenu id="indexadores" value="#{periodicoGSBean.periodico.indexadores}" label="Selecione aqui os indexadores" filter="true"  filterMatchMode="startsWith" style="width:80%"  >  
                                    <f:selectItems value="#{periodicoGSBean.listaIndexadores}" />  
                                </p:selectCheckboxMenu>


                            </h:panelGrid>
                            <h:panelGrid columns="1" width="99%" style="text-align: center" >
                                <h:outputText value="Indexador não cadastrado:" style="width: 20%;" />

                            </h:panelGrid>
                            <h:panelGrid columns="2" width="99%" style="text-align: center" >
                                <p:inputText value="#{periodicoGSBean.indexadorNaoCadastrado}" style="width: 80%" />
                                <p:commandButton value="Adicionar" action="#{periodicoGSBean.addIndexadorNovo()}"  update="indexadores" />
                            </h:panelGrid>






                            <h:panelGrid columns="1" width="99%" style="text-align: center" >








                            </h:panelGrid>
                            <h:panelGrid columns="1" width="99%" style="text-align: center"  >
                                <h:outputText value="Descrição (Limite de 1500 caracters):"/>
                                <p:editor value="#{periodicoGSBean.periodico.descricao}" width="900"  maxlength="1500" style="text-align: center" />
                            </h:panelGrid>

                            <br/>
                            <p:panel header="Tema de publicação / Palavras-chave" style="background-color: #D0D0D0;font-size: large " >


                                <h:panelGrid columns="2" width="99%" >
                                    <p:selectOneMenu id="temas" value="#{periodicoGSBean.palavraChaveSelecionada.id}" style="width:95%"  
                                                     filter="true" filterMatchMode="startsWith"  >  
                                        <f:selectItem itemLabel="Selecione" itemValue=""   />  
                                        <f:selectItems value="#{temaBean.listaTemas}" var="t" itemLabel="#{t.tema}" itemValue="#{t.id}" />
                                    </p:selectOneMenu> 
                                    <p:commandButton value="Cadastrar" action="#{periodicoGSBean.addPalavraChave()}" update="temas, tCadastrados"  >

                                    </p:commandButton>
                                </h:panelGrid>
                                <p:commandLink oncomplete="dPC.show()" update=":form:display3" >
                                    Não encontrou a palavra-chave?
                                </p:commandLink>
                                <br/><br/>

                                <p:panel header="Palavras-chave Selecionadas" style="background-color: #A0A0A0" >
                                    <p:dataTable id="tCadastrados" value="#{periodicoGSBean.palavrasChaves}" var="te" style="width: 70%" >
                                        <p:column headerText="Palavra-chave" style="width: 98%">
                                            #{te.tema}
                                        </p:column>
                                        <p:column headerText="Remover">
                                            <p:panelGrid columns="1" style="text-align:center">
                                                <p:commandButton action="#{periodicoGSBean.removerPalavraChave()}" icon="ui-icon-trash"  style="width: 2%" update="tCadastrados" >
                                                    <f:setPropertyActionListener target="#{periodicoGSBean.palavraChaveSelecionada}" value="#{te}" />

                                                </p:commandButton>
                                            </p:panelGrid>     

                                        </p:column>
                                    </p:dataTable>
                                </p:panel>
                            </p:panel>
                            <br/>
                            <p:messages id="messages" showDetail="true" autoUpdate="true" closable="true" escape="false" /> 
                            <p:panel header="Editores" style="background-color: #D0D0D0;font-size: large " >


                                <h:panelGrid columns="2" width="99%" >

                                    <h:outputText value="Editor: " style="width: 20%" /> 
                                    <p:selectOneMenu id="autores" value="#{periodicoGSBean.editorSelecionado.editor.id}" style="width:95%"  
                                                     filter="true" filterMatchMode="startsWith"  >  
                                        <f:selectItem itemLabel="Selecione" itemValue=""   />  
                                        <f:selectItems value="#{autorBean.listaAutoresSimplificado}" var="a" itemLabel="#{a.nome}" itemValue="#{a.id}" />
                                    </p:selectOneMenu>
                                    <h:outputText value="Ano de Início: " style="width: 20%" /> 
                                    <p:inputText  id="anoInicio" value="#{periodicoGSBean.editorSelecionado.anoInicio}" style="width: 80%" /> 
                                    <h:outputText value="Ano de Término: " style="width: 20%" /> 
                                    <p:inputText  id="anoFim" value="#{periodicoGSBean.editorSelecionado.anoFim}" style="width: 80%" />
                                    <p:commandButton value="Adicionar" action="#{periodicoGSBean.addEditor()}" update="autores, anoInicio, anoFim, aCadastrados"  >

                                    </p:commandButton>
                                </h:panelGrid>

                                <br/><br/>

                                <p:panel header="Editores Selecionadas" style="background-color: #A0A0A0" >
                                    <p:dataTable id="aCadastrados" value="#{periodicoGSBean.editores}" var="editor" style="width: 95%" >
                                        <p:column headerText="Nome" style="width: 80%;white-space: normal" >
                                            #{editor.editor.nome} #{editor.editor.instituicaoAutor.nome}
                                        </p:column>
                                        <p:column headerText="Ano Início" style="width: 8%">
                                            #{editor.anoInicio}
                                        </p:column>
                                        <p:column headerText="Ano Término" style="width: 8%">
                                            #{editor.anoFim}
                                        </p:column>


                                        <p:column headerText="Remover">
                                            <p:panelGrid columns="1" style="text-align:center">
                                                <p:commandButton action="#{periodicoGSBean.removerEditor()}" icon="ui-icon-trash"  style="width: 4%" update="aCadastrados" >
                                                    <f:setPropertyActionListener target="#{periodicoGSBean.editorSelecionado}" value="#{editor}" />

                                                </p:commandButton>
                                            </p:panelGrid>     

                                        </p:column>
                                    </p:dataTable>
                                </p:panel>
                            </p:panel>


                            <br/>





                        </div>
                    </p:panel>
                    <h:panelGrid columns="2" width="99%"  style="text-align:center" >
                        <p:commandButton value="Cadastrar" action="#{periodicoGSBean.cadastrar()}"  update="form" />
                        <p:commandButton value="Cancelar" action="/indexSistema.xhtml" ajax="false" />
                    </h:panelGrid>

                    <p:dialog id="dPalavraChave" header="Cadastrar Palavra-Chave" widgetVar="dPC" >  
                        <p:panel id="display3"  >
                            <b><h:outputText value="Palavra-Chave:" /></b><br/>
                            <h:inputText value="#{temaBean.tema.tema}" />
                            <p:commandButton actionListener="#{temaBean.cadastroTema()}" oncomplete="dPC.hide()" value="Cadastrar" update=":form:temas" >
                                <f:setPropertyActionListener target="#{trabalhoGSBean.listaTemas}" value="#{null}" />
                            </p:commandButton>
                        </p:panel>

                    </p:dialog>  

                </h:form>    
            </f:view>
        </ui:define>
    </ui:decorate>
</html>